﻿using System;
using System.Collections.Generic;
using System.Linq;
using Trainings;
using TrainingsApp.Model;
using TrainingsApp.Logic;
using System.Drawing;


namespace TrainingsApp.IPADApp {
    public partial class Test : System.Web.UI.Page {
        protected void Page_Load(object sender, EventArgs e) {
            Guid preview = new Guid("D7F3BE51-DBF4-4285-B98D-0DDC94F1EF27");
            int teacherId = 151;
            int classId = 2;


            //var resultList = TS_Preview_Result_Logic.TS_Preview_Result_GetTypicalByPreviewIdAndClassId(preview, classId);
            //if (resultList != null && resultList.Count > 0) {
            //    foreach (TS_Preview_Result_Entity r in resultList) {
            //        r.ReferencePercent = Math.Round((r.GroupCount * 100.0 / (r.GroupTotal == 0 ? 1 : r.GroupTotal)), 2);
            //    }
            //}

            //double[] yval = new double[resultList.Count];
            //string[] xval = new string[resultList.Count];

            //int i = 0;
            //foreach (var item in resultList.OrderByDescending(u => u.ReferencePercent)) {
            //    yval[i] = item.ReferencePercent;
            //    xval[i] = item.GroupName.ToString();
            //    i++;
            //}

            //this.Chart1.Series["Series1"].Points.DataBindXY(xval, yval);

            //var colorManager = ChartColorManager.GetInstance();
            //for (int j = 0; j < this.Chart1.Series["Series1"].Points.Count; j++) {
            //    this.Chart1.Series["Series1"].Points[j].Color = colorManager.GetColor();
            //}
        }


        protected void btnLogOut_Click(object sender, EventArgs e) {
            Response.Redirect("~/UserLogout.ashx");
        }
    }


    public class ChartColorManager {
        static readonly System.Drawing.Color[] colors;

        static ChartColorManager() {
            colors = new System.Drawing.Color[7];
            colors[0] = Color.FromArgb(255, 155, 155);
            colors[1] = Color.FromArgb(255, 204, 153);
            colors[2] = Color.FromArgb(255, 255, 153);
            colors[3] = Color.FromArgb(204, 255, 204);
            colors[4] = Color.FromArgb(51, 204, 204);
            colors[5] = Color.FromArgb(75, 165, 255);
            colors[6] = Color.FromArgb(204, 153, 255);
        }

        int m_index = 0;
        public ChartColorManager() {
            m_index = 0;
        }

        public static ChartColorManager GetInstance() {
            return new ChartColorManager();
        }

        public Color GetColor() {
            if (m_index >= colors.Length) { m_index = 0; }
            return colors[m_index++];
        }

    }
}